$(function(){
    $("#uploadForm").submit(uploadForm);
});
function uploadForm(){
    $.ajax({
        url: "http://upload-z2.qiniup.com",
        method: "post",
        //不要把表单的内容转成字符串
        processData: false,
        //不设置上传类型
        contentType: false,
        data: new FormData($("#uploadForm")[0]),
        success: function (data){
            if(data && data.code == 0){
                $.post(
                    CONTEXT_PATH + "/user/header/url",
                    {"fileName": '/' + $("input[name='key']").val()},
                    function (data){
                        data = $.parseJSON(data);
                        if(data.code == 0){
                            window.location.reload();
                        }else {
                            alert(data.msg);
                        }
                    }
                )
            }else {
                alert("上传失败");
            }
        }
    })
    return false;
}